import request from '@/utils/request';
import type {MembershipPlan, WordPlan, RechargeOrder, RecentLog, UserInfo} from './types';

/**
 * 获取充值套餐列表
 */
export const getRechargePlans = () => {
  return request<{ membershipPlans: MembershipPlan[], wordPlans: WordPlan[] }>({
    url: '/payment/plans',
    method: 'get'
  });
};

export const getRecentLog = () => {
  return request<RecentLog[]>({
    url: '/payment/recent',
    method: 'get'
  });
};

export const getUserInfo = () =>{
  return request<UserInfo>({
    url: '/payment/user_info',
    method: 'get'
  });
}

/**
 * 创建充值订单
 * @param params
 */
export const createRechargeOrder = (params: {
  planId: number;
  planType: 'membership' | 'words';
  paymentMethod: 'wechat' | 'alipay';
}) => {
  // 实际API调用（当后端API准备好后取消注释）
  return request<RechargeOrder>({
    url: '/payment/order/create',
    method: 'post',
    data: params
  });
};

/**
 * 获取订单状态
 * @param orderId 订单ID
 */
export const getOrderStatus = (orderId: string) => {
  // 实际API调用（当后端API准备好后取消注释）
  return request<{ status: Number}>({
    url: `/payment/order/status`,
    params: {"orderId": orderId},
    method: 'get'
  });
};

/**
 * 获取用户充值记录
 */
export const getRechargeRecords = () => {
  // 实际API调用（当后端API准备好后取消注释）
  return request({
    url: '/payment/records',
    method: 'get'
  });
}; 